package hiho.ku._1032._2;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for (int i = 0; i < n; i++)
			run(in);
	}
	
	private static void run(Scanner in) {
		String s = in.next();
		s = insertSharps(s);
		
		int mid = s.length() / 2;
		int ans = 1;
		while (ans <= mid && s.charAt(mid + ans) == s.charAt(mid - ans))
			ans++;
		
		// left
		for (int i = 1; mid - i >= ans; i++) {
			int center = mid - i;
			if (s.charAt(center - ans) != s.charAt(center + ans))
				continue;
			boolean check = true;
			for (int j = ans; j > 0; j--)
				if (s.charAt(center - j) != s.charAt(center + j)) {
					check = false;
					break;
				}
			if (check) {
				int p = ans + 1;
				while (p <= center && s.charAt(center - p) == s.charAt(center + p))
					p++;
				ans = p;
			}
		}
		
		// right
		for (int i = 1; mid - i >= ans; i++) {
			int center = mid + i;
			if (s.charAt(center - ans) != s.charAt(center + ans))
				continue;
			boolean check = true;
			for (int j = ans; j > 0; j--)
				if (s.charAt(center - j) != s.charAt(center + j)) {
					check = false;
					break;
				}
			if (check) {
				int p = ans + 1;
				while (center + p < s.length() && s.charAt(center - p) == s.charAt(center + p))
					p++;
				ans = p;
			}
		}
		
		System.out.println(ans - 1);
	}
	
	private static String insertSharps(String s) {
		StringBuilder b = new StringBuilder();
		b.append('#');
		for (int i = 0; i < s.length(); i++)
			b.append(s.charAt(i)).append('#');
		return b.toString();
	}

}
